<%@ Page Title="Lang_Language List" Language="C#" AutoEventWireup="true" ValidateRequest="false" CodeBehind="Lang_LanguageList.aspx.cs" Inherits="Youz.CreditRepay.Manage.Lang_LanguageList" %>

<script>
    //loadCSS("assets/plugins/gritter/css/jquery.gritter.css");

    var requireJS = [
        //"assets/plugins/gritter/js/jquery.gritter.min.js"
    ];

    loadJS(requireJS);
</script>
<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-heading" data-original-title>
                <h2><i class="fa fa-align-justify"></i><span class="break"></span><%: R(LanguageModule.Lang_Language, "Lang_Language", "Lang_Language") %></h2>
                <div class="panel-actions"></div>
            </div>
            <div class="panel-body">
                <div class="alert alert-danger" style="display: none;">
                    <button type="button" class="close" data-dismiss="alert">×</button><strong><i class="fa fa-warning"></i></strong><span class="content"></span>
                </div>
                <div class="row" style="margin-bottom:20px;">
                    <div class="col-sm-12">
                        <form class="form-inline">
                            <div class="form-group">
                                <select id="SModuleName" class="form-control required">
                                    <option value=""><%: Lang_LanguageBLL.LanguageByManage(LanguageModule.M_Common, "All", "所有") %></option>
                                    <% List<string> list = new Lang_LanguageBLL().GetModule(siteType);
                                       foreach (string item in list)
                                       {
                                    %>
                                    <option value="<%= item %>"><%= item %></option>
                                    <%
                                   }
                                    %>
                                </select>
                            </div>
                            <div class="form-group">
                                <input type="text" id="SLanguageKey" class="form-control" placeholder="<%: R(LanguageModule.Lang_Language, "LanguageKey", "语言KEY") %>">
                            </div>
                            <div class="form-group">
                                <input type="text" id="SLanguageValue" class="form-control" placeholder="<%: R(LanguageModule.Lang_Language, "LanguageValue", "语言值") %>">
                            </div>
                            <div class="form-group">
                                <button type="button" class="btn btn-primary" id="btnSearch">
                                    <i class="fa fa-search "></i>
                                    <%: R(LanguageModule.M_Common, "Query") %></button>
                            </div>
                        </form>
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-12">
                        <div class="form-group">
                            <a href="#" class="btn btn-info" id="btnAdd"><i class="fa fa-plus"></i>
                                <%: R(LanguageModule.M_Common, "Add") %></a>
                            <a href="#" class="btn btn-info" id="btnEdit"><i class="fa fa-edit "></i>
                                <%: R(LanguageModule.M_Common, "Edit") %></a>
                            <a href="#" class="btn btn-info" id="btnDelete"><i class="fa fa-trash-o "></i>
                                <%: R(LanguageModule.M_Common, "Delete") %></a>
                        </div>
                    </div>
                </div>
                <table id="table" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%"></table>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="modalItem">
    <div class="modal-dialog">
        <div class="modal-content">
                <form id="frm" class="form-horizontal" method="post" enctype="multipart/form-data" action="Lang/Handlers/Lang_LanguageHandler.ashx?type=save">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">新增</h4>
            </div>
            <div class="modal-body">
                <input type="hidden" id="isEdit" name="isEdit" />
                    <div class="form-group">
                        <label class="control-label" for="ModuleName"><%: R(LanguageModule.Lang_Language, "ModuleName", "模块名称") %></label>
                        <div class="controls">
                            <select id="ModuleName" name='ModuleName' class="form-control required">
                                <option value=""><%: Lang_LanguageBLL.LanguageByManage(LanguageModule.M_Common, "All", "所有") %></option>
                                <% list = new Lang_LanguageBLL().GetModule(siteType);
                                   foreach (string item in list)
                                   {
                                %>
                                <option value="<%= item %>"><%= item %></option>
                                <%
                                    }
                                %>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label" for="LanguageKey"><%: R(LanguageModule.Lang_Language, "LanguageKey", "语言KEY") %></label>
                        <div class="controls">
                            <input type="text" id="LanguageKey" name="LanguageKey" maxlength="200" class="form-control required" />
                        </div>
                    </div>
                    <% 
                       foreach (Lang_LanguageType item in listType)
                       {
                    %>
                    <div class="form-group">
                        <label class="control-label" for="<%:item.LanguageCode %>"><%: item.LanguageName %></label>
                        <div class="controls">
                            <input type="text" id="<%:item.LanguageCode %>" name="<%:item.LanguageCode %>" maxlength="200" class="form-control required" />
                        </div>
                    </div>
                    <%} %>
                    <div class="malert alert-danger" style="display: none;">
                        <button type="button" class="close" data-dismiss="alert">×</button><span class="content"></span></div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-success" type="submit" id="btnSubmit"><%: R(LanguageModule.M_Common, "btnSubmit", "保存修改") %></button>
                <button class="btn btn-default" type="button" id="btnCancel" data-dismiss="modal"><%: R(LanguageModule.M_Common, "btnCancel", "取消") %></button>
            </div>
                </form>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->

<script type="text/javascript">
    var dt;
    var $modalItem = $("#modalItem");
    var dataLangType = <%=Youz.CreditRepay.BLL.Core.GetJsonByObject(listType)%>;
    var flag = false;

    function save(title, row) {

        $modalItem.find(".modal-title").html(title);
        $modalItem.modal("show");

        if(row){
            $("#isEdit").val(1);
            $("#ModuleName").val(row.ModuleName);
            $("#LanguageKey").val(row.LanguageKey);
            $.each(dataLangType, function(i,v){ 
                $("#" + v.LanguageCode).val(row[v.LanguageCode]);
            });
        }
    }

    $(function () {
        $("#frm").validate({
            errorElement: "span"
        });

        $("#frm").ajaxForm({
            dataType: 'json',
            beforeSubmit: function (arr, $form, options) {
                if (flag) {
                    return false;
                }
                else {
                    flag = true;
                    return true;
                }
            },
            success: function (data) {
                if (data.isSuccess) {
                    dt.ajax.reload(function(){}, false);
                    $modalItem.modal("hide");
                }
                else {
                    $(".malert > .content").html(data.message);
                    $(".malert").show();
                }
                flag = false;
            }
        });

        dt = $('#table').DataTable({
            "ajax": {
                "url": 'Lang/Handlers/Lang_LanguageHandler.ashx?type=list',
                "type": "POST",
                "dataSrc": "data",
                "data": function (d) {
                    d.ModuleName = $("#SModuleName").val();
                    d.LanguageKey = $("#SLanguageKey").val();
                    d.LanguageValue = $("#SLanguageValue").val();
                }
            },
            "columns": [

                    { "data": 'ModuleName', "title": "<%: R(LanguageModule.Lang_Language, "ModuleName", "模块名称") %>" },
                    { "data": 'LanguageKey', "title": "<%: R(LanguageModule.Lang_Language, "LanguageKey", "语言KEY") %>" },	
                    <% 
                       foreach (Lang_LanguageType item in listType)
                       {
                %>
                    { "data": '<%: item.LanguageCode %>', "title": "<%: item.LanguageName %>" },	
                    <%
                       }
                %>
            ]
        });

        $("#btnSearch").click(function(){
            dt.ajax.reload();
        });

        //delete selected row
        $('#btnDelete').click(function () {
            if ($('#table tbody tr.selected').length > 0) {
                jconfirm("<%: R(LanguageModule.M_Common, "DeleteConfirm") %>", function () {
                    //console.log(dt.row('.selected').data());
                    var row = dt.row('.selected').data();
                    $.post("Lang/Handlers/Lang_LanguageHandler.ashx?type=delete<%: WebHelper.Get("st") %>", { ModuleName: row.ModuleName, LanguageKey: row.LanguageKey }, function (data) {
                        if (data) {
                            if (data.isSuccess) {
                                dt.ajax.reload(function(){}, false);

                                $.gritter.add({
                                    title: '<%: R(LanguageModule.M_Common, "TipSuccess") %>',
                                    text: data.message,
                                    class_name: 'gritter-success'
                                });

                                $('#table tbody tr.selected').remove();
                            }
                            else{
                                $(".alert > .content").html(data.message);
                                $(".alert").show();
                            }
                        }
                    }, "json");
                });
            }
            else {
                $(".alert > .content").html("<%: R(LanguageModule.M_Common, "SelectRecord") %>");
                $(".alert").show();
            }
        });

        $("#btnAdd").click(function () {
            $("#frm").resetForm();
            save("新增");
        });

        //delete selected row
        $('#btnEdit').click(function () {
            if ($('#table tbody tr.selected').length > 0) {
                var row = dt.row('.selected').data();
                save("编辑", row);
            }
            else {
                $(".alert > .content").html("<%: R(LanguageModule.M_Common, "SelectRecord") %>");
                $(".alert").show();
            }
        });

    });
</script>
